import { NavBar } from 'antd-mobile'
import { PropTypes } from 'prop-types'
import './NavBarAgain.scss'
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom'
function NavBarAgain(props) {
    let navigate = useNavigate(),
            location = useLocation(),
            [usp] = useSearchParams();
    let { title } = props
    const handleBack = () => {
        // 特殊：登录页 & to的值是/detail/xxx
        let to = usp.get('to');
        if(location.pathname === '/login' && /^\/detail\/\d+$/.test(to)){
            navigate(to,{replace:true});
            return;
        }
        navigate(-1);
    }
    return <NavBar className='navbar-again-box' onBack={handleBack}>{title}</NavBar>
}
NavBarAgain.defaultProps = {
    title: '个人中心'
}
NavBarAgain.propTypes = {
    title: PropTypes.string
}
export default NavBarAgain